package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"hotel/model/mysql"

	"hotel/userrpc/internal/svc"
	"hotel/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInfoLogic) UserInfo(in *userrpc.UserInfoRequest) (*userrpc.UserInfoResponse, error) {
	// todo: add your logic here and delete this line

	var find mysql.User
	mysql.DB.Debug().Where("id = ?", in.Userid).Find(&find)
	fmt.Println(find)
	if find.ID == 0 {
		return nil, fmt.Errorf("用户不存在")
	}
	user := mysql.User{
		Model:      gorm.Model{ID: uint(in.Userid)},
		HouseName:  in.HouseName,
		HouseImage: in.HouseImage,
	}
	mysql.DB.Debug().Updates(&user)
	return &userrpc.UserInfoResponse{Id: int64(user.ID)}, nil
}
